﻿// 常用字符处理函数
///获取参数值
function getUrlParam(param)
{
   var url = window.location.search.substring(1);
   var paramArray = url.split("&");
   if(paramArray.length != 0)
       for(var i = 0;i < paramArray.length;i++)
       {
            var pramArraySub = paramArray[i].split("=");
            if(pramArraySub[0] == param && pramArraySub[1] != "undefined")
            return pramArraySub[1];
       }
   else
   {
        paramArray = url.split("=");
        if(paramArray[0] == param && paramArray[1] != "undefined")
            return paramArray[1];
   }
   return "";
}
///关闭网页
function ClosePage()
{
     window.opener = new Object();
     self.close();
}
///判断全角字符
function ValidateChar(para)
{
    var strTmp = new String();   
    strTmp = para;   

    for(var i = 0; i < strTmp.length; i++){   
        if(strTmp.charCodeAt(i) > 128)   
            window.alert("全角字符：" + strTmp.charAt(i));
        else   
            window.alert("半角字符：" + strTmp.charAt(i));
    }
}
/// 获取下拉菜单文本项的值
function GetDropdownListText(selectName)
{
    var options = $(selectName).getElementsByTagName('option');
    options = $A(options);
    var opt = options.find( function(employee){
        return (employee.value == $F(selectName));
    });
    return opt.innerHTML;
}
function IsNull(o)
{
    return ("undefined" == typeof(o) || "unknown" == typeof(o) || null == o);
}
function Trim(s) { 
    s = s.replace(/^\s+|\s+$/g, ''); 
    var chars = String.fromCharCode(0x0085, 0x00A0, 0x2028, 0x2029, 0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000);
    for (var i = 0; i < chars.length; i++)
    {
        var iChar = chars.charCodeAt(i);
        var sChar = "";
        if (iChar < 0x100)
        {
            sChar += "00";
        }
        else if (iChar < 0x1000)
        {
            sChar += "0";
        }

        sChar += iChar.toString(16);

        s = s.replace(new RegExp("^\\u" + sChar + "+|\\u" + sChar + "+$", "g"), '');
    }

    return s;
}
function TrimSpaces(s)
{
    if (s != null)
    {
        s = Trim(s);
        return s.replace(/\s+/g,' ');
    }

    return null;
}
var LOCID_DIALOG_OFFSET_WIDTH = "0";
var LOCID_DIALOG_OFFSET_HEIGHT = "0";
var LOCID_UI_DIR = "LTR";
var DialogRetryReturnValue = "___RETRY___";
/// 打开网页对话框
function openStdDlg(sPath, oArgs, iWidth, iHeight, bResizable, bModeless, sCustomWinParams)
{
    if (IsNull(sCustomWinParams))
    {
        sCustomWinParams = "";
    }

    // 	By default all modal dialog is resizable
    if(IsNull(bResizable))
    {
        bResizable = true;
    }
    // Take into consideration any global increases in dialog size.  Used by localization teams.
    // Only use these increased sizes if the dialog is already resizeable.  If it is not resizeable then the increased sizes will
    // most likely not help much because the dialog probably has a fixed layout.
    if (bResizable)
    {
        iWidth	+= parseInt(LOCID_DIALOG_OFFSET_WIDTH, 10);
        iHeight += parseInt(LOCID_DIALOG_OFFSET_HEIGHT, 10);
    }
    // Adjust height for screen size.
    iWidth	= getAdjustedWidthForScreen(iWidth);
    iHeight	= getAdjustedHeightForScreen(iHeight);
    bResizable = (!IsNull(bResizable) && bResizable) ? "yes" : "no";
    // Get the left and top margin.
    var iLeft = getLeftMargin(iWidth);
    var iTop = getTopMargin(iHeight);
    if (LOCID_UI_DIR == "RTL")
        iLeft = screen.availWidth-iLeft-iWidth;
    sCustomWinParams = "dialogWidth:" + iWidth + "px;dialogHeight:" + iHeight + "px;dialogLeft=" + iLeft + "px;dialogTop=" + iTop + "px;help:0;status:1;scroll:0;center:1;resizable:" + bResizable + ";" + sCustomWinParams;
    if (IsNull(bModeless) || !bModeless)
    {
        return safeWindowShowModalDialog(sPath, oArgs, sCustomWinParams);
    }
    else
    {
        return safeWindowShowModelessDialog(sPath, oArgs, sCustomWinParams);
    }
}
function safeWindowShowModalDialog(sUrl, vArguments, sFeatures)
{
    // Make sure the dialog arguments are set.
    if (vArguments === null)
    {
        vArguments = "";
    }
    var returnVar = null;
    try
    {
        do
        {
            returnVar = window.showModalDialog(sUrl, vArguments, sFeatures);
        }
        while (returnVar === DialogRetryReturnValue);
    }
    catch (e)
    {
        handlePopupBlockerError();
    }
    return returnVar;
}
function safeWindowShowModelessDialog(sUrl, vArguments, sFeatures)
{
    var windowOpened = null;
    try
    {
        windowOpened = window.showModelessDialog(sUrl, vArguments, sFeatures);
    }
    catch (e)
    {
    }
    if (IsNull(windowOpened))
    {
        handlePopupBlockerError();
    }
    return windowOpened;
}
//This variable is set as a window is about to open, then can be checked in the window.onload (or similar).  Don't use it in any
// other event handlers as it is global and may have changed due to other windows opening.
// Also, there is a chance that two separate clicks could cause windows to open and the first value set gets overriden
// by the second click.  This would be a rare occurance, but useage of this variable should take this into account.
var _bWindowSizeAdjusted = false;
// Given a screen width will adjust it to fit in the current screen.  If it is empty it will default it to the application default.
function getAdjustedWidthForScreen(iX)
{
    var iWidth = iX;
    if (IsNull(iX) || iX == 0)
    {
        iX = (screen.availWidth >= 1000) ? 820 : 750;
    }
    iX = (iX >= screen.availWidth) ? screen.availWidth : iX;
    _bWindowSizeAdjusted = (iX != iWidth);
    return iX;
}
// Given a screen height will adjust it to fit in the current screen.  If it is empty it will default it to the application default.
function getAdjustedHeightForScreen(iY)
{
    if (IsNull(iY) || iY == 0)
    {
        return (screen.availHeight >= 600) ? 560 : 510;
    }
    else
    {
        return (iY >= screen.availHeight) ? screen.availHeight : iY;
    }
}
// Calculate the left and top margin to place the form in center.
function getLeftMargin(iX)
{
    var iLeft = 0;
    if ((screen.availWidth - iX) > 0)
    {
        iLeft = (screen.availWidth - iX)/2;
    }
    return iLeft;
}
function getTopMargin(iY)
{
    var iTop = 0;
    if ((screen.availHeight - iY) > 0)
    {
        iTop = (screen.availHeight - iY)/2;
    }
    return iTop;
}
function buildWinName(s)
{
    if (s) return s.toLowerCase().replace(/[-\{\}:]/g, "");
    var d = new Date();
    return d.getTime();
}
var IS_PATHBASEDURLS = true;
var ORG_UNIQUE_NAME = "appWebs";
function appendOrgName(sUrl)
{
    var sNewUrl = sUrl;	
    if (IS_PATHBASEDURLS) 
    {
        if(sUrl.substring(sUrl.length - 1) == "/")
        {
            sNewUrl = sUrl + ORG_UNIQUE_NAME;
        }	
        else
        {
            sNewUrl = sUrl + "/" + ORG_UNIQUE_NAME;
        }
    }
    return sNewUrl;
}
function prependOrgName(sUrl)
{	
    var sNewUrl = sUrl;	
    if (IS_PATHBASEDURLS && ORG_UNIQUE_NAME.length > 0) 
    {
        sNewUrl = "/" + ORG_UNIQUE_NAME + sUrl;
    }
    return sNewUrl;
}
function stripOrgName(sUrl)
{
    stripOrgNameWithForce(sUrl, false);
}
function stripOrgNameWithForce(sUrl, bForce)
{
    var sNewUrl = sUrl ;
    if (IS_PATHBASEDURLS || bForce && ORG_UNIQUE_NAME.length > 0)
    {
        if (sNewUrl.substr(0, 1) != "/")
        {
            sNewUrl = "/" + sNewUrl ;
        }

        sNewUrl = sNewUrl.replace("/" + ORG_UNIQUE_NAME,"");
    }

    return sNewUrl ;
}
function handlePopupBlockerError()
{
    alert(LOCID_POPUP_BLOCKER_ERROR +  window.location.hostname);
}
var LOCID_POPUP_BLOCKER_ERROR = "信息报送系统 \u7a97\u53e3\u65e0\u6cd5\u6253\u5f00\uff0c\u53ef\u80fd\u5df2\u88ab\u5f39\u51fa\u7a97\u53e3\u963b\u6b62\u7a0b\u5e8f\u6240\u963b\u6b62\u3002\u8bf7\u5c06\u8fd9\u53f0 信息报送系统 \u670d\u52a1\u5668\u6dfb\u52a0\u5230\u60a8\u7684\u5f39\u51fa\u7a97\u53e3\u963b\u6b62\u7a0b\u5e8f\u5141\u8bb8\u6253\u5f00\u65b0\u7a97\u53e3\u7684\u7ad9\u70b9\u7684\u5217\u8868\u4e2d\x3a";

function openStdWin(sPath, sName, iX, iY, sCustomWinFeatures)
{
    iX = getAdjustedWidthForScreen(iX);
    iY = getAdjustedHeightForScreen(iY);
    // Get the left and top margin.
    var iLeft = getLeftMargin(iX);
    var iTop = getTopMargin(iY);
    var sWinDir = "left";
    if (LOCID_UI_DIR == "RTL")
    sWinDir = "right";
    return safeWindowOpen(sPath, sName, "width=" + iX + ",height=" + iY + ",status=1,resizable=1," + sWinDir + "=" + iLeft + ",top=" + iTop + (IsNull(sCustomWinFeatures) ? "" : "," + sCustomWinFeatures));
}
// The following functions do try/catch, and display the popup blocker error message as an alert when the window fails to open.
function safeWindowOpen(sUrl, sName, sFeatures, bReplace)
{
    var windowOpened = null;
    try
    {
        windowOpened = window.open(sUrl, sName, sFeatures, bReplace);
    }
    catch (e)
    {
    }
    if (IsNull(windowOpened))
    {
        handlePopupBlockerError();
    }
    return windowOpened;
}
/* 获取下拉菜单选定项的文本值 */
function GetDrpListText(_obj, tagetObjId)
{
    if (_obj.value != "") 
    {     
        for (var i = 0; i < _obj.options.length; i++) {         
            if (_obj.options[i].selected == true) 
            {         
                document.getElementById(tagetObjId).value = _obj.options[i].text;
            }
        }
    }
    else
    {
        document.getElementById(tagetObjId).value = "";
    }
}

/* 获取下拉菜单选定项的文本值 */
function GetDrpListTextToTargetObj(objId, tagetObjId)
{
    var _obj = document.getElementById(objId);
    if (_obj.value != "") 
    {     
        for (var i = 0; i < _obj.options.length; i++) {         
            if (_obj.options[i].selected == true) 
            {         
                document.getElementById(tagetObjId).value = _obj.options[i].text;
            }
        }
    }
    else
    {
        document.getElementById(tagetObjId).value = "";
    }
}
function GetDrpListText(objId)
{
    var _obj = document.getElementById(objId);
    if (_obj.value != "") 
    {     
        for (var i = 0; i < _obj.options.length; i++) {         
            if (_obj.options[i].selected == true) 
            {         
                return _obj.options[i].text;
            }
        }
        return "";
    }
    else
    {
        return "";
    }
}

function findObj(theObj, theDoc) {
    var p, i, foundObj;
    if (!theDoc) {
        theDoc = document;
    }
    if ((p = theObj.indexOf("?")) > 0 && parent.frames.length) {
        theDoc = parent.frames[theObj.substring(p + 1)].document;
        theObj = theObj.substring(0, p);
    }
    if (!(foundObj = theDoc[theObj]) && theDoc.all) {
        foundObj = theDoc.all[theObj];
    }
    for (i = 0; !foundObj && i < theDoc.forms.length; i++) {
        foundObj = theDoc.forms[i][theObj];
    }
    for (i = 0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) {
        foundObj = findObj(theObj, theDoc.layers[i].document);
    }
    if (!foundObj && document.getElementById) {
        foundObj = document.getElementById(theObj);
    }
    return foundObj;
}
function CardUtils_GetBirthday(val, objId) {
    var bthControl = findObj(objId, document);
    var birthdayValue = "";
    if (15 == val.length) {
        //15位身份证号码 
        birthdayValue = val.charAt(6) + val.charAt(7);
        if (parseInt(birthdayValue) < 10) {
            birthdayValue = '20' + birthdayValue;
        }
        else {
            birthdayValue = '19' + birthdayValue;
        }

        birthdayValue = birthdayValue + '-' + val.charAt(8) + val.charAt(9) + '-' + val.charAt(10) + val.charAt(11);
    }
    if (18 == val.length) {
        //18位身份证号码 
        birthdayValue = val.charAt(6) + val.charAt(7) + val.charAt(8) + val.charAt(9) + '-' + val.charAt(10) + val.charAt(11) + '-' + val.charAt(12) + val.charAt(13);
    }
    bthControl.value = birthdayValue;
}
function CardUtils_GetSex(val) {
    var sexCode;
    //15位身份证号码 
    if (15 == val.length) {
        if (parseInt(val.charAt(14) / 2) * 2 != val.charAt(14))
            sexCode = "0";
        else
            sexCode = "1";
    }
    //18位身份证号码 
    if (18 == val.length) {
        if (parseInt(val.charAt(16) / 2) * 2 != val.charAt(16))
            sexCode = "0";
        else
            sexCode = "1";
    }

    return sexCode;
}